<?php

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
include_once 'MySqlDataAccessHelper.php';

/**
 * Description of Word
 *
 * @author Phuong Vu
 */
class Status {

    public $ID_Status;
    public $Vocabulary;
    public $Grammar;
    public $Listen;
    public $Test;
    public $Write;
    public $ID_User;
    public $ID_lesson;
    public $Value;

    public function GetStatusByIDUser($id) {
        try {
            $connection = new MySqlDataAccessHelper();
            $connection->open();

            $sql = "SELECT * FROM status WHERE ID_User=" . $id;
            $result = $connection->executeQuery($sql);

            $status = new Status();
            while ($row = mysql_fetch_object($result)) {
                $status = $row;
            }

            $connection->close();

            return $status;
        } catch (Exception $e) {
            $connection->close();
            return false;
        }
    }

    public function SetStatusListen($idUser, $idLesson) {
        try {
            $connection = new MySqlDataAccessHelper();
            $connection->open();

            $sql = "UPDATE status SET Listen = 1 WHERE ID_User = $idUser AND ID_lesson = $idLesson";
            $result = $connection->executeQuery($sql);

            $connection->close();

            return true;
        } catch (Exception $e) {
            $connection->close();
            return false;
        }
    }



    public function GetStatusListen($idUser, $idLesson) {
        try {
            $connection = new MySqlDataAccessHelper();
            $connection->open();

            $sql = "SELECT Listen FROM Status WHERE ID_User = $idUser AND ID_lesson = $idLesson";
            $result = $connection->executeQuery($sql);
            
            $isSet = 0;
            while ($row = mysql_fetch_object($result)) {
                            $isSet = $row;
                        }
            $connection->close();

            return $isSet;
        } catch (Exception $e) {
            $connection->close();
            return false;
        }
    }
}